/*
 * @Author: WuFeng <763467339@qq.com>
 * @Date: 2022-03-22 12:12:49
 * @LastEditTime: 2022-03-22 12:27:32
 * @LastEditors: WuFeng <763467339@qq.com>
 * @Description: 多语言控制
 * @FilePath: \vue3-element-plus-web\src\store\modules\language.js
 * @Copyright 版权声明
 */
// import { getLanguage } from '@/language'
import { getLanguageType, setLanguageType } from '@/language/handleLanguage'

const language = {
  state: {
    lang: getLanguageType()
  },

  mutations: {
    // 切换语言
    SET_LANG: (state, lang) => {
      state.lang = lang
    }
  },

  actions: {
    // 设置语言
    SetLanguage({ commit }, lang) {
      return new Promise((resolve) => {
        // console.log('--')
        // console.log(lang)
        commit('SET_LANG', lang)
        // localStorage.setItem('locale', lang)
        setLanguageType(lang)
        // locale.use(element[lang])
        // console.log(element[lang])
        // console.log(locale)
        resolve(lang)
      })
    }
  }
}

export default language
